***** RUN DO_MASTER.do ***** do "$Do_files\DO_MASTER.do"

global program "OA_TableB310"
cap log close
cap log using "$Log_files\log_$program$today", replace

**** REPLICATION OF TABLE B.3.10 ****

clear all
set mem 2g
set more off

// Import data

use $Data\data_news_voting, clear

// Get controls

global ctrl_base	"sh_lde lpop_A sh_F sh_F_new sh_cspsup sh_sec sh_ter lmean_reink lmean_reink2 charact_altitude charact_altitude_std sh_active sh_young sh_prot sh_M mk com_property"
global ctrl_plus	"mean_votation lcrSR_F_N"
global fe			"charact_agglo"
global cluster		"charact_agglo"

// Column 1
		
reghdfe oui instr_mk hqcLR_F_N_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing
estimates store RF_ctrl

// Column 2

reghdfe endog_mk instr_mk hqcLR_F_N_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	
estimates store FS_ctrl
test instr_mk
estadd scalar F_fs=r(F)

// Column 3

reghdfe oui $ctrl_plus $ctrl_base hqcLR_F_N_mk (endog_mk = instr_mk) ///
	if sample_hq00dstr==1, ///
	vce(cluster $cluster) absorb($fe) stages(first, eform(exp(beta))) keepsing old
estimates store TSLS_ctrl

// Column 4
		
reghdfe oui instr_eta_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	
estimates store RF_eta_ctrl

// Column 5

reghdfe endog_mk instr_eta_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing
estimates store FS_eta_ctrl
test instr_eta_mk
estadd scalar F_fs=r(F)
		
// Column 6

reghdfe oui $ctrl_plus $ctrl_base (endog_mk = instr_eta_mk) ///
	if sample_hq00dstr==1, ///
	vce(cluster $cluster) absorb($fe) stages(first, eform(exp(beta))) keepsing old
estimates store TSLS_eta_ctrl

// Labels

la var endog_mk 		"Crime News Exposure ($ \mathtt{CNE} $)"
la var instr_mk 		"[0.1em] HQ $ \mathtt{CPD} $ ($ \mathtt{HQC} $)" 
la var instr_eta_mk 	"[0.1em] HQ $ \mathtt{CPD} $ Residual  ($ \hat{\eta} $)"
la var lcrSR_F_N		"[0.1em] Local $ \mathtt{CPD} $"
la var mean_votation 	"[0.1em] Past Vote Outcomes"
la var hqcLR_F_N_mk		"[0.1em] HQ $ \mathtt{CPD} $ Long-Run ($ \overline{\mathtt{HQC}} $)" 

// For Paper
	
estout RF_ctrl FS_ctrl TSLS_ctrl RF_eta_ctrl FS_eta_ctrl TSLS_eta_ctrl ///
	using "$Results\\$program.tex", replace style(tex) type label	///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(N r2_a F_fs, lab("Observations" "Adjusted $ R^2 $" "First-stage F-statistic") fmt(0 3 2)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(endog_mk lcrSR_F_N mean_votation instr_mk hqcLR_F_N_mk instr_eta_mk) ///
	order(endog_mk lcrSR_F_N mean_votation instr_mk hqcLR_F_N_mk instr_eta_mk) ///
	title(News and voting: Instrumenting with residuals) ///	
	prehead("\begin{table}[!h]" ///
	"\begin{center}" ///
	"\begin{threeparttable}" ///
	"\begin{footnotesize}" ///
	"\caption{\small{@title}\label{$program}}" ///
	"\begin{tabular*}{\columnwidth}{@{\extracolsep{\stretch{1}}}l*{@M}{c}@{}}" ///
	"\hline" "\hline" ///	
	"\\" ///
	"Instrument 		&\multicolumn{3}{c}{HQ Crime Prop. Differential ($ \mathtt{HQC} $)} 				&\multicolumn{3}{c}{HQ Crime Prop. Residual  ($ \hat{\eta} $)} \\" ///
	"Additional Controls	&\multicolumn{3}{c}{HQ Crime Prop. Diff. LR ($ \overline{\mathtt{HQC}} $)} 				& \\" ///
	"					\cmidrule(lr){2-4}												\cmidrule(lr){5-7} 							" ///
	"Specification		&\multicolumn{1}{c}{RF}			&\multicolumn{1}{c}{FS}			&\multicolumn{1}{c}{2SLS}		&\multicolumn{1}{c}{RF}		&\multicolumn{1}{c}{FS}		&\multicolumn{1}{c}{2SLS} \\" ///
	"					\cmidrule(lr){2-2} 				\cmidrule(lr){3-4}				\cmidrule(lr){5-5}				\cmidrule(lr){6-7}" ///
	"Dependent Variable &\multicolumn{1}{c}{\%Yes} 		&\multicolumn{1}{c}{$ \mathtt{CNE} $}		&\multicolumn{1}{c}{\%Yes}		&\multicolumn{1}{c}{\%Yes} 		&\multicolumn{1}{c}{$ \mathtt{CNE} $}		&\multicolumn{1}{c}{\%Yes}	\\" ///
	"					\cmidrule(lr){2-4}												\cmidrule(lr){5-7} 							" ///
	"					&\multicolumn{1}{c}{(1)} 		&\multicolumn{1}{c}{(2)}  		&\multicolumn{1}{c}{(3)} 		&\multicolumn{1}{c}{(4)}  	&\multicolumn{1}{c}{(5)} &\multicolumn{1}{c}{(6)} \\") ///
	posthead("\hline" ///
	"\\") ///
	prefoot("\\" ///
	"\hline") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" /// 
	"\end{footnotesize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" /// 
	"The unit of observation is a municipality. " ///
	"Standard errors clustered at agglomeration level in parentheses. " ///
	"{$^c$} significant at 10\%; {$^b$} significant at 5\%; {$^a$} significant at 1\%. " ///
	"Columns (1) to (3) present 2SLS estimation based on the instrument computed as the short-run Crime Propensity Differential in newspaper headquarter areas ($ \mathtt{HQC} $) " ///
	"and simultaneously controlling for the long-run Crime Propensity Differential in newspaper headquarter areas ($ \overline{\mathtt{HQC}} $). " ///
	"Columns (4) to (6) using using the estimated residual $\hat{\eta}_{m}$ of a regression of the short-run crime-rate differential on its long-run counterpart. " ///
	"Columns (1) and (4) present the reduced form estimation; Columns (2) and (5) the first-stage; Columns (3) and (6) the second-stage estimates. " ///
	"All regressions include the full vector of controls of Table \ref{Main_Table2}. " ///
	"" ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

cap log close
